package net.jjjshop.front.mapper.order;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import io.swagger.models.auth.In;
import net.jjjshop.common.entity.order.Order;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;


/**
 * 订单记录表 Mapper 接口
 *
 * @author jjjshop
 * @since 2022-07-04
 */
@Repository
public interface OrderMapper extends BaseMapper<Order> {
    /**
     * 普通商品购买数量
     * @param userId
     * @param productId
     * @return
     */
    Integer getHasBuyOrderNum(@Param("userId") Integer userId, @Param("productId") Integer productId);

    /**
     * 活动商品购买数量
     * @param userId
     * @param productId
     * @return
     */
    Integer getPlusOrderNum(@Param("userId") Integer userId, @Param("productId") Integer productId,@Param("orderSource") Integer orderSource);

    Order getOneOrder(Integer js);

    @Select("SELECT COUNT(b.shop_supplier_id) from jjjshop_order a LEFT JOIN(\n" +
            "SELECT shop_supplier_id FROM jjjshop_supplier WHERE shop_type=#{shopType}\n" +
            ")b ON a.shop_supplier_id=b.shop_supplier_id  WHERE a.user_id=#{userId} and a.pay_status =20")
    Integer getUserOnePay(@Param("userId") Integer userId,@Param("shopType") Integer shopType);

    @Select("SELECT COUNT(b.shop_supplier_id) from jjjshop_order a LEFT JOIN(\n" +
            "SELECT shop_supplier_id FROM jjjshop_supplier WHERE shop_supplier_id=#{shopId} and shop_type=3\n" +
            ")b ON a.shop_supplier_id=b.shop_supplier_id  WHERE a.user_id=#{userId} and a.pay_status =20")
    Integer getUserShopOnePay(@Param("userId")Integer userId,@Param("shopId")Integer shopId);
}
